﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Vds2465Telegrams;

namespace Vds2465Parser
{
	internal static class GenParse_ConnectionPath
	{
		#region private constants

		private const byte ConnectThroughRequestByte = 0x08;
		private const byte CallbackRequestByte = 0x10;
		private const byte CallbackExecutionByte = 0x18;
		private const byte ConnectThroughExecutedByte = 0x80;

		#endregion private constants

		#region internal methods

		internal static byte GenerateByte(eConnectionPath conPath)
		{
			byte conPathByte = 0x0;

			switch (conPath)
			{
				case eConnectionPath.CallbackExecution:
					conPathByte = CallbackExecutionByte;
					break;
				case eConnectionPath.CallbackRequest:
					conPathByte = CallbackRequestByte;
					break;
				case eConnectionPath.ConnectThroughExecuted:
					conPathByte = ConnectThroughExecutedByte;
					break;
				case eConnectionPath.ConnectThroughRequest:
					conPathByte = ConnectThroughRequestByte;
					break;
				default:
					// TODO handle error (unknown value for eHistory)
					break;
			}

			return conPathByte;
		}

		internal static bool ParseByte(byte conPathByte, out eConnectionPath conPath)
		{
			// set default value
			bool bRetVal = true;
			conPath = eConnectionPath.CallbackRequest;

			switch (conPathByte)
			{
				case ConnectThroughRequestByte:
					conPath = eConnectionPath.ConnectThroughRequest;
					break;
				case CallbackRequestByte:
					conPath = eConnectionPath.CallbackRequest;
					break;
				case CallbackExecutionByte:
					conPath = eConnectionPath.CallbackExecution;
					break;
				case ConnectThroughExecutedByte:
					conPath = eConnectionPath.ConnectThroughExecuted;
					break;

				default:
					// TODO handle error (unknown value for conPathByte)
					bRetVal = false;
					break;
			}

			return bRetVal;
		}

		#endregion internal methods
	}
}
